#!/bin/bash

SERVER=$1;
HOST=$2;

#SERVER=10.145.20.44

if [ -z "$HOST" ] && [ "${HOST+xxx}" = "xxx" ]; then 
   echo "Warn: host is empty, taking default host IP=192.168.2.119."
	HOST=192.168.2.119
else
   echo -n "Info: host is: " 
	echo $HOST;
fi

if [ -z "$SERVER" ] && [ "${SERVER+xxx}" = "xxx" ]; then 
   echo "Warn: server identification is empty, use 'tomcat', 'node', 'yaws', 'cowboy', 'apache'"
	exit 1;
fi

# This is Tomcat 7 / Java 7
if [ "${SERVER}" = "tomcat" ]; then
	PORT=18080
	URI="/jsfks/performance?value=benchmark"
fi

# This is nodeJS 
if [ "${SERVER}" = "nodejs" ]; then
	PORT=38080
	URI="/?value=benchmark"
fi

# This is yaws erlang
if [ "${SERVER}" = "yaws" ]; then
	PORT=8080
	URI="/performance.yaws/?value=benchmark"
fi

# This is yaws erlang
if [ "${SERVER}" = "cowboy" ]; then
	PORT=8181
	URI="/?value=benchmark"
fi

# This is Apache reverse proxy before nodeJS server
if [ "${SERVER}" = "apache" ]; then
	PORT=80
	URI="/nodejs?value=benchmark"
fi

if [ -z "$PORT" ]; then 
   echo -n "Error: variable PORT is not set. Use 'tomcat', 'node', 'yaws', 'cowboy', 'apache'"
	exit 1;
fi

echo "** START **"
echo -n $HOST
echo -n ":"
echo -n $PORT
echo $URI

RATES="100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500 525 550 575 600 625 650 675 700 725 750 775 800 825 850 875 900 925 950 975 1000"

for rate in $RATES
do
   httperf --timeout=5 --client=0/1 --server=${HOST} --port=${PORT} --uri=${URI} --rate=${rate} --send-buffer=4096 --recv-buffer=16384 --num-conns=5000 --num-calls=10
done

